package com.space.myapollo.config;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 抽象类，controller拦截器，打印请求日志
 *
 * @version <pre>
 *          Author	Version		Date		Changes
 *          zyj 	1.0  		2018年12月2日 	Created
 *
 *          </pre>
 * @since 1.
 */
@Component
@Slf4j
public class CorslHandlerInterceptor extends AbstractHandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {       //请求进入这个拦截器

        return true;
    }

    @Override
    public List<String> getAddPathPatterns() {
        List<String> list = new ArrayList<String>();
        list.add("/**");
        return list;
    }

    @Override
    public List<String> getExcludePathPatterns() {
        return new ArrayList<String>();
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        response.addHeader("Access-Control-Allow-Origin","*");
    }
}